sessionStorage.setItem("userId","134852213520081106"); 
sessionStorage.setItem("name","任丽琴");
sessionStorage.setItem("jobnumber","1005");
sessionStorage.setItem("deptId","55088496");
var corp = GetQueryString('corp');
sessionStorage.setItem("corp",corp);
var nowDate = getDay(0);
var starttimecalendar = new lCalendar();
var endtimecalendar = new lCalendar();
starttimecalendar.init({
	'trigger': '#startDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
endtimecalendar.init({
	'trigger': '#endDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
function ICalendarClick(){
//	onload()
}
if(sessionStorage.getItem("name")){
	document.getElementById("startDate").value=nowDate;
	document.getElementById("endDate").value=nowDate;
	getselect();
 	getvideo();
	getshop();
	//$('#name').text(sessionStorage.getItem("name"));
}else{	
	var _config ;
	$.ajax({
		type : "post",
		data:JSON.stringify({"pageUrl":location.href.replace(/\\&/g,'%26'),"corp":corp}),
		contentType: "application/json; charset=utf-8",
		async: false,
		url : "../dingding/getconfig",
		dataType : "json",
		success : function(suc) {
			_config = suc.config;
		}
	}); 
	dd.ready(function() {
		dd.runtime.permission.requestAuthCode({
			corpId: _config.corpId,
			onSuccess: function(result) {
				getuserId(result);
			},
			onFail : function(err) {
				alert("错误"+JSON.stringify(err))
			}
			
		});
	});
	function getuserId(result){
		$.ajax({
			url : '../dingding/ddEasy',
			type : 'POST',
			data:JSON.stringify({"code":result.code,"token":_config.token}),
			contentType: "application/json; charset=utf-8",
			dataType : "json",
			success : function(suc) {
				if(suc.status == '1002'){
					sessionStorage.setItem("userId",suc.userJson.userid);
					sessionStorage.setItem("name",suc.userJson.name);
					sessionStorage.setItem("jobnumber",suc.userJson.jobnumber);
					sessionStorage.setItem("deptId",suc.userJson.department);
				}else{
					alert(suc.msg);
				}
					document.getElementById("startDate").value=nowDate;
					document.getElementById("endDate").value=nowDate;		
					getselect();
			        getvideo();
					getshop();
					//$('#name').text(sessionStorage.getItem("name"));
			},
			error : function(xhr, errorType, error) {
				alert(errorType + ', ' + error);
			}
		});
	}
	dd.error(function(err) {
		alert('dd error: ' + JSON.stringify(err));
	});
}
$(document).ready(function(){
	$('#searchButton').on('click',function(){
		if($('#startDate').val() > $('#endDate').val()){
			alert("开始日期不能大于结束日期")
		}else{
			getvideo();
		}
	});
});	
function getselect(){
	$('#shopcode').html("");
	var shopcode = sessionStorage.getItem("jobnumber");
	var m = shopcode.split(",");
	if(shopcode == '0'){
			$('#shopcode').append('<option value="0" >所有</option>');
	}else{
		for(var i=0;i<m.length;i++){
			$('#shopcode').append('<option value="'+m[i]+'" >'+m[i]+'</option>');
		}
	}
}
function getvideo(){
	trStr = "";
    $("#shujvdiv").html("");
	$.ajax({  
		url: "../../unite_platform/mobile_page/get_video"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"shopcode":$('#shopcode').val(),"startdate":$('#startDate').val(),"enddate":$('#endDate').val()}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			var trStr=""; 
			for (var i = 0; i < res.data.length; i++) {
			trStr   +='<tr>'
					+'<td>'+(res.data[i].shopcode=='0'?'所有门店        ':res.data[i].shopcode)+'</td>'
					+'<td>'+res.data[i].uploaddate.substring(0,10)+'</td>'
					+'<td onclick = "video_detail(\''+res.data[i].id+'\')"><img class="layui-upload-img"  style="width:38px;height:38px" src="../genius/layui/images/video1.png"></td>'
					+'</tr>'
			}
			$('#shujvdiv').append(trStr);
		}
	});
}
function getshop(){
	if($('#shopcode').val() == '0' || $('#shopcode').val() == 0){
		$('#shopname').text("所有门店        ");
	}else{
		$.ajax({  
			url: "../../unite_platform/mobile_page/get_shop"
			,type:'post'
			,async: false
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({"shopcode":$('#shopcode').val()}) 
			,dataType:'json'
			,success: function(res){
				console.log(res);
				$('#shopname').text(res.data[0].deptcode+res.data[0].deptname);
			}
		});
	}
}
function video_detail(id){
	 var  url = "video_detail?id="+id;//此处拼接内容
	 window.location.href = url;
}
function upload(){
	 var  url = "upload_video?shopcode="+$('#shopcode').val();//此处拼接内容
	 window.location.href = url;
}